package com.example.androidbighomework.utils;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashMap;
import java.util.Map;

public class SaveChangePersonInfo {
    private static final String CHANGENAME="changename";
    private static final String CHANGEPHONE="changephone";
    private static final String CHANGEBIRTH="changebirth";
    //将changename，changephone，changebirth以键值对的形式保存到personinfos.xml文件
    public static boolean savePersonInfo(Context context,String changename,String changephone,String changebirth){
        SharedPreferences sp=context.getSharedPreferences("personinfos",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putString(CHANGENAME,changename);
        editor.putString(CHANGEPHONE,changephone);
        editor.putString(CHANGEBIRTH,changebirth);
        editor.commit();
        return true;
    }
    //取出personinfos.xml文件里的changename，changephone，changebirth的数据以键值对的形式返回给Map集合
    public static Map<String,String> getPersonInfo(Context context){
        Map<String,String> map=new HashMap<>();
        SharedPreferences sp=context.getSharedPreferences("personinfos",Context.MODE_PRIVATE);

        map.put("changename",sp.getString(CHANGENAME,"昵称"));
        map.put("changephone",sp.getString(CHANGEPHONE,"17692010071"));
        map.put("changebirth",sp.getString(CHANGEBIRTH,"2001/3/4"));
        return map;
    }

}
